  $(function(){
	  //显示权限按钮
	  var parentUUID = $("input[name='parentUUID']").val();
   	  $.permission.showButton(parentUUID,"actionBtnArea");
   	  var basePath = getBasePath();
   	  //表格初始化
   	  var checkStatus = $("#checkStatus").val();
      var deleteFlag =  $("#deleteFlag").val();
      var saveType =  $("#saveType").val();
	  $.dataGridEasyUI.initTable({
		  pageId:"#articleListPage",
		  gridId:"#articleList",
		  url:getBasePath()+'article/getArticleList.do',
		  toolbarId:"#articleListPage .tb_toolbar",
		  queryParams: {
        	 deleteFlag:deleteFlag,
        	 checkStatus:checkStatus,
        	 saveType:saveType
    	  },
		  columns:[[
  		            {field:'id',checkbox:true},
  		            {field:'articleType',title:'所属分类',width:'10%'},
  		            {field:'articleTitile',title:'标题',width:'21%',formatter: function(value,row,index){
  		            	var imageUrl = "";
	  		  	    	if(row.imageUrl!=""){
	  		  	    		imageUrl = getImgPath()+row.imageUrl;
	  		  	    		console.log("imageUrl_:"+imageUrl);
	  		  	    	}
	  		  	    	
	  		  	    	var cellHtml = '<a class="fancybox-effects-a" href="'+imageUrl+'">'+
	  		              '<img src="'+imageUrl+'" class="thumbnail" title="点我可以放大哦" onerror="this.src=\''+getBasePath()+'/error/images/default_article.jpg\'"  width="64" align="left">'+
	  		            '</a><a href="javascript:showDetail('+row.id+')" style="color:#046DAD">'+row.articleTitile+'</a>';
	  		            return cellHtml;
  					  }
                    },
  		            {field:'parentCompany',title:'阅读/点赞',width:'11%',formatter: function(value,row,index){
  		            	var cellHtml = row.readCount+"/"+row.zanCount;
	  		            return cellHtml;
  					  }},
  		            {field:'yearNo',title:'状态/上线',width:'11%',formatter: function(value,row,index){
  		            	var statusMsg = "";
	  		  	    	if(row.status==1){
	  		  	    		statusMsg = "正常开放";
	  		  	    	}else if(row.status==2){
	  		  	    		statusMsg = "屏弊中";
	  		  	    	}else if(row.status==3){
	  		  	    		statusMsg = "仅发布者可看";
	  		  	    	}
	  		  	    	
	  		  	        //上线按钮
	  			    	var onlineMsg = "已上线";
	  			    	if(row.isOnline==0){
	  			    		onlineMsg = "未上线";
	  			    	}else if(row.isOnline==2){
	  			    		onlineMsg = "已上线";
	  			    	}
  		            	var cellHtml = statusMsg+"/"+onlineMsg;
	  		            return cellHtml;
  					  }},
  					{field:'checkStatus',title:'状态/上线',width:'11%',formatter: function(value,row,index){
  						if (row.checkStatus==0){
  							return "<font color='#f58220'><b>待审核</b></font>";
  						} else if (row.checkStatus==1){
  							return "<font color='#7fb80e'><b>审核通过<br>审核意见："+row.checkMsg+"</b></font>";
  						} else if (row.checkStatus==2){
  							return "<font color='#d71345'><b>未通过<br>审核意见："+row.checkMsg+"</b></font>";
  						}
  					  }},
  		            {field:'licenseNo',title:'进库类型',width:'11%',formatter: function(value,row,index){
	  		            //上线按钮
  		            	var saveTypeMsg = "";
	  		  	    	if(row.saveType==0){
	  		  	    		saveTypeMsg = "手动录入保存";
	  		  	    	}else if(row.saveType==1){
	  		  	    		saveTypeMsg = "网站抓取";
	  		  	    	}
  		            	var cellHtml = saveTypeMsg;
	  		            return cellHtml;
  					  }},
  		            {field:'createTime',title:'创建时间',width:'11%'}
  		        ]]
	  });
  
  //新增按钮绑定事件
  $("#addDataLink").bind("click",function(){
	  window.location.href=getBasePath()+"manage/article/editArticle.jsp";
	  /*$.dataGridEasyUI.initEditWindow({
		  url:getBasePath()+"manage/article/editArticle.jsp",
		  title:"添加资讯信息",
		  actionType:"add"
	  });*/
  });
  
  //更新按钮绑定事件
  $("#updateDataLink").bind("click",function(){
	  $.dataGridEasyUI.initEditWindow({
		  url:getBasePath()+"manage/article/editArticle.jsp?showType=window",
		  title:"编辑资讯信息",
		  actionType:"update",
		  windowType:"iframe",
		  width: $(window).width()*0.95,
		  height: $(window).height()*0.95
	  });
  });
  
  //批量删除
  $("#batchDeleteLink").bind("click",function(){
	  $.dataGridEasyUI.batchDeleteData({
		  url:getBasePath()+"/article/batchDelArticleForHS.do",
	  });
  });
  
  //单个删除
  $("#singleDeleteLink").bind("click",function(){
	  $.dataGridEasyUI.batchDeleteData({
		  url:getBasePath()+"/article/delArticle.do",
	  });
  });
  
  //显示详情
  $("#showDetailLink").bind("click",function(){
	  $.dataGridEasyUI.initEditWindow({
		  url:getBasePath() + "article/getArticleDetail.do",
		  title:"展示详情",
		  actionType:"detail",
		  width:650,
		  height:350
	  });
  });


   //图片弹窗
	$(".fancybox-effects-a").fancybox({
		helpers: {
			title : {
				type : 'outside'
			},
			overlay : {
				speedOut : 0
			}
		}
	});
})

//检索数据
function seachData(){
   var searChObj = new Object(); 
   var formId = "searchForm";
   $("#"+formId).find("input").each(function(i){
	   searChObj[$(this).attr("name")] = $(this).val();
   });
   
   $("#"+formId).find("select").each(function(i){
	   searChObj[$(this).attr("name")] = $(this).val();
   });
   tableObject.datagrid({
	     queryParams:searChObj
   })
}

//查看详细信息
function showDetail(id){
  $.dataGridEasyUI.initEditWindow({
	  url:getBasePath() + "article/getArticleDetail.do?id="+id,
	  title:"查看资讯明细",
	  actionType:"detail",
	  width: $(window).width()*0.95,
	  height: $(window).height()*0.95
  })
}

//永久删除数据
function batchDelInDB(){
  $.dataGridEasyUI.batchDeleteInDB({
	  url:getBasePath()+"/article/batchDelArticle.do",
  });
}
                  
//恢复数据
function rebackData(){
	$.dataGridEasyUI.batchDeleteInDB({
		  url:basePath+"/article/batchRebackData.do"
	});
}

//审核信息
function checkSingleData(){
	$.dataGridEasyUI.initEditWindow({
		  url:getBasePath() + "manage/article/checkArticle.jsp",
		  title:"审核文章",
		  actionType:"check",
	      width: 650,
          height: 300
	  });
}